﻿using MetroGS.AppClass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MetroGS.Pages
{
    /// <summary>
    /// Interaction logic for UCSearch.xaml
    /// </summary>
    public partial class UCSearch : UserControl
    {
        SQL ClassSQL = new SQL();

        public UCSearch()
        {
            InitializeComponent();
        }

        private void tb_search_KeyUp(object sender, KeyEventArgs e)
        {
            if (!Char.IsDigit((char)KeyInterop.VirtualKeyFromKey(e.Key)) & e.Key != Key.Back | e.Key == Key.Enter)
            {
                if (e.Key == Key.Enter)
                {
                    string sql = "SELECT * FROM gamecentral WHERE gamename LIKE '%" + tb_search.Text + "%' ORDER BY gamename";
                    ClassSQL.gamessearch(this, sql); ClassSQL.gamessearch(this, sql);
                }
                if (e.Key == Key.Escape)
                {
                    tb_search.Text = "";
                    lb_searchresult.Items.Clear();
                    tb_result.Text = "No result found";
                }
                else
                {
                    string sql = "SELECT * FROM gamecentral WHERE gamename LIKE '%" + tb_search.Text + "%' ORDER BY gamename";
                    ClassSQL.gamessearch(this, sql); ClassSQL.gamessearch(this, sql);
                }
            }
        }

        private void bu_search_Click(object sender, RoutedEventArgs e)
        {
            string sql = "SELECT * FROM gamecentral WHERE gamename LIKE '%" + tb_search.Text + "%' ORDER BY gamename";
            ClassSQL.gamessearch(this, sql); ClassSQL.gamessearch(this, sql);
        }
    }
}
